package com.sevenGroup.pawnshop.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

/**
 * <p>
 * 
 * </p>
 *
 * @author sevenGroup
 * @since 2022-02-16
 */
@Data
@EqualsAndHashCode(callSuper = false)
@ApiModel("账户对象")
public class Account implements Serializable, UserDetails {

    private static final long serialVersionUID = 1L;

    @TableId(value = "account_id",type = IdType.AUTO)
    @ApiModelProperty("账号ID")
    private Integer accountId;
    @ApiModelProperty("账号")
    private String accountUsername;
    @ApiModelProperty("密码")
    private String accountPassword;
    @ApiModelProperty("手机号")
    private String accountTel;
    @ApiModelProperty("角色权限")
    private List<String> roles;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        if(roles!=null&&roles.size()>0){
            ArrayList<GrantedAuthority> gas = new ArrayList<>();
            for (String role : roles) {
                gas.add( () -> role);
            }
            return gas;
        }
        return null;
    }

    @Override
    public String getPassword() {
        return this.accountPassword;
    }

    @Override
    public String getUsername() {
        return this.accountUsername;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}
